﻿<UserControl x:Class="Chapters.Chapter03.CircularMinuteTimer"
						 xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
						 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
						 xmlns:Runner="clr-namespace:FSharp.Chapter3;assembly=FSharpLibrary">
	<UserControl.Resources>
		<Runner:ProgressToAngleConverter x:Key="ProgressConverter" />

		<Style TargetType="ProgressBar">
			<Setter Property="Template">
				<Setter.Value>
					<ControlTemplate TargetType="ProgressBar">
						<Grid>
							<Ellipse Stroke="Black"
											 Fill="{TemplateBinding Background}" />
							<Ellipse Stroke="Black"
											 Margin="40"
											 Fill="White" />
							<Runner:Arc StrokeThickness="30"
														Stroke="{TemplateBinding BorderBrush}"
														Margin="5">
								<Runner:Arc.StartAngle>
									<MultiBinding Converter="{StaticResource ProgressConverter}">
										<Binding Path="Minimum"
														 RelativeSource="{RelativeSource TemplatedParent}" />
										<Binding Path="."
														 RelativeSource="{RelativeSource TemplatedParent}" />
									</MultiBinding>
								</Runner:Arc.StartAngle>
								<Runner:Arc.EndAngle>
									<MultiBinding Converter="{StaticResource ProgressConverter}">
										<Binding Path="Value"
														 RelativeSource="{RelativeSource TemplatedParent}" />
										<Binding Path="."
														 RelativeSource="{RelativeSource TemplatedParent}" />
									</MultiBinding>
								</Runner:Arc.EndAngle>
							</Runner:Arc>

							<TextBlock Text="{Binding Value, RelativeSource={RelativeSource TemplatedParent}, StringFormat=\{0:0\}}"
												 Foreground="{TemplateBinding Background}"
												 VerticalAlignment="Center"
												 HorizontalAlignment="Center"
												 FontSize="72"
												 FontWeight="Bold" />
						</Grid>
					</ControlTemplate>
				</Setter.Value>
			</Setter>
		</Style>
	</UserControl.Resources>

	<Grid>
		<ProgressBar x:Name="_progress"
								 Minimum="0"
								 Maximum="60"
								 Value="30"
								 Background="#7f7f7f"
								 BorderBrush="#ffbd67" />
	</Grid>

	<UserControl.Triggers>
		<EventTrigger RoutedEvent="Window.Loaded">
			<BeginStoryboard>
				<Storyboard RepeatBehavior="Forever">
					<DoubleAnimation From="0"
													 To="60"
													 Storyboard.TargetName="_progress"
													 Storyboard.TargetProperty="Value"
													 Duration="0:0:3" />
				</Storyboard>
			</BeginStoryboard>
		</EventTrigger>
	</UserControl.Triggers>
</UserControl>
